<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>sessionStorage和localStorage</title>
</head>
<body>
    <input type="button" id="setStorage" value="设置sessionStorage">
    <input type="button" id="getStorage" value="获取sessionStorage">
    <script>
        document.getElementById("setStorage").onclick = function(){
            sessionStorage.setItem("a",100);
            sessionStorage.setItem("student",JSON.stringify({name:"张飞",age:20}));
            let ary = [
                {name:"张飞",age:20},
                {name:"关羽",age:21},
                {name:"刘备",age:22},
                {name:"曹操",age:23}

            ];
            sessionStorage.setItem("students",JSON.stringify(ary))
        }
        document.getElementById("getStorage").onclick = function(){
            console.log(sessionStorage.getItem("a"));
            let student = JSON.parse(sessionStorage.getItem("student"));
            // console.log("student:",typeof student,student.name);
            let students = JSON.parse(sessionStorage.getItem("students"));
            console.log(students);
        }
    </script>
</body>
</html>